package com.user.manage;

import java.sql.*;

public class SqlserverJdbcTest {
    public static void main(String[] args) throws SQLException {
        String driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";

        String url = "jdbc:sqlserver://localhost:1433;DatabaseName=testdb2;encrypt=true;trustServerCertificate=true";
        String username = "sa";
        String password = "123456";

        Connection connection = DriverManager.getConnection(url, username, password);
        System.out.println(connection);

        ResultSet resultSet = connection.prepareStatement("select * from test_user").executeQuery();
        ResultSetMetaData metaData = resultSet.getMetaData();
        for (int i = 1; i <= metaData.getColumnCount(); i++) {
            System.out.println(metaData.getColumnName(i) + "\t" + metaData.getColumnLabel(i));
        }
        while (resultSet.next()) {
            System.out.println(resultSet.getInt("id") + "\t" + resultSet.getString("username"));
        }
    }
}
